﻿using System;
using System.Collections.Generic;
using System.Linq;
using Xenta.Utils;

namespace Xenta.Operations
{
    /// <summary>
    /// Exposes the import operation interface.
    /// </summary>
    public interface IImportOperation : IOperation<Int32>
    {
        #region Properties

        /// <summary>
        /// Gets or sets the operation specific properties.
        /// </summary>
        IDictionary<String, String> Properties
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the collection of objects to be imported.
        /// </summary>
        IEnumerable<IDictionary<String, String>> Objects
        {
            get;
            set;
        }

        #endregion
    }

    /// <summary>
    /// Exposes the export operation interface.
    /// </summary>
    public interface IExportOperation : IOperation<IEnumerable<IDictionary<String, String>>>
    {
        #region Properties

        /// <summary>
        /// Gets or sets the operation specific properties.
        /// </summary>
        IDictionary<String, String> Properties
        {
            get;
            set;
        }

        #endregion
    }

    /// <summary>
    /// Represents the import operation base.
    /// </summary>
    /// <remarks>
    /// The central part of the import system. This 
    /// kind of operations receives a dictionary, 
    /// processes it and returns the number of imported 
    /// results.
    /// </remarks>
    public abstract class ImportOperation : Operation<Int32>, 
        IImportOperation
    {
        #region Properties

        /// <summary>
        /// Gets or sets the operation specific properties.
        /// </summary>
        public IDictionary<String, String> Properties
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the collection of objects to be imported.
        /// </summary>
        public IEnumerable<IDictionary<String, String>> Objects
        {
            get;
            set;
        }

        #endregion

        #region Utilities

        protected override Err Validate(IUnitOfWork uow)
        {
            if(Objects == null || !Objects.Any())
                return Err.Of(this).No("Objects");
            return base.Validate(uow);
        }

        #endregion
    }

    /// <summary>
    /// Represents the export query operation.
    /// </summary>
    /// <remarks>
    /// The central part of the export system. This 
    /// kind of operations collects the required data 
    /// and represents the collected data as a dictionary.
    /// </remarks>
    public abstract class ExportOperation : Operation<IEnumerable<IDictionary<String, String>>>, 
        IExportOperation
    {
        #region Properties

        /// <summary>
        /// Gets or sets the operation specific properties.
        /// </summary>
        public IDictionary<String, String> Properties
        {
            get;
            set;
        }

        #endregion
    }
}
